<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>角色信息</title>
    <link rel="stylesheet" href="../static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../static/css/public.css" media="all">
    <script src="/static/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
</head>
<body>
<form id="addType" class="layui-form" action="" method="get">
    <input type="hidden" id="roleId" name="roleId"/>
    <div class="layui-form-item" style="margin-top: 50px">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
            <input id="roleName" name="roleName" readonly="readonly"  lay-verify="required" type="text" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text" style="margin-top: 30px">
        <label class="layui-form-label">角色描述</label>
        <div class="layui-input-block">
            <textarea id="roleDescribe" name="roleDescribe" class="layui-textarea"  lay-verify="required" cols="62" rows="6"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-left: 280px">
            <button id="subbtn" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认修改</button>
        </div>
    </div>
</form>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script th:inline="javascript" type="text/javascript">
    let data={
        roleId: null,
        roleName: null,
        roleDescribe: null,
    }
    $(function (){
        let role=[[${role}]];
        $('#roleId').val(role.roleId);
        $('#roleName').val(role.roleName);
        $('#roleDescribe').val(role.roleDescribe);

        $('#addType').submit(function (e){
            let formData=new FormData(this);
            data.roleId=formData.get("roleId");
            data.roleName=formData.get("roleName");
            data.roleDescribe=formData.get("roleDescribe");
            $.ajax({
                type:"post",
                url:"/role/editRole",
                data:data,
                success:function (res){
                    if(res.code===200){
                        layer.msg(res.message,{time:5000,icon:1,offset:[15]});
                        let index=parent.layer.getFrameIndex(window.name);
                        setTimeout(function (){
                            window.parent.location.reload();//刷新父页面
                            parent.layer.close(index);
                        },1500);
                    }else{
                        layer.msg(res.message,{time:5000,icon:1,offset:[15]});
                    }
                },
                error:function (error){
                    layer.msg(error,{time:5000,icon:2,offset:[15]})
                }
            })
            e.preventDefault();
        })

    })
</script>
</body>
</html>